package com.jsbj.user.controller;


import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysDictType;
import com.jsbj.user.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-dict-type")
@ApiIgnore
@Api(value = "字典类型", tags = "字典类型")
public class SysDictTypeController extends BaseController {

    @Autowired
    private ISysDictTypeService sysDictTypeService;

    @ApiOperation(value = "添加字典类型")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<Integer> add(@RequestBody SysDictType sysDictType) throws Exception {
        return new ResultBean<>(sysDictTypeService.add(sysDictType));
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @PostMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    public ResultBean<PageReq> getList(@RequestBody String inParam) {
        return new ResultBean<PageReq>(getPage(sysDictTypeService.getList(inParam)));
    }

    @ApiOperation(value = "删除")
    @ResponseBody
    @PostMapping("/delete")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean delete(@RequestParam String id) throws Exception {
        return new ResultBean<Integer>(sysDictTypeService.delete(id));
    }

    @GetMapping("/selectData")
    public ResultBean<List<SysDictType>> selectData() {
        return new ResultBean<List<SysDictType>>(sysDictTypeService.selectData());
    }
}

